<template>
  <div id="components-form-demo-advanced-search">
    <a-form class="ant-advanced-search-form" :form="form"  :label-col="{ span: 5 }" :wrapper-col="{ span: 12 }">
      <a-form-item label=""  >
        <span>姓　　名 ：</span>
        <a-input v-decorator="['professorName']" placeholder="请输入姓名"/>
        </a-form-item>

      <a-form-item label="">
        <span>性　　别 ：</span>
            <j-dict-select-tag type="list" v-decorator="['professorSex']" :trigger-change="true" dictCode="sex" placeholder="请选择专家性别"/>
          </a-form-item>

      <a-form-item label="">
        <span>毕业院校 ：</span>
            <a-input v-decorator="['professorSchool']" placeholder="请输入毕业院校"></a-input>
          </a-form-item>

      <a-form-item label="">
        <span>所学专业 ：</span>
              <j-tree-select
                v-model="marjorId"
                placeholder="请选择专业"
                dict="major,name,id"
                pidField="parentId"
                v-decorator="['professorMajor']">
              </j-tree-select>
            </a-form-item>

      <a-form-item label="">
        <span>学　　历 ：</span>
            <j-dict-select-tag type="list" v-decorator="['professorEducationBackground']" :trigger-change="true" dictCode="education" placeholder="请选择学历"/>
          </a-form-item>
<!--        </a-col>-->
<!--      </a-row>-->
<!--      <a-row :gutter="24">-->
<!--        <a-col :span="6">-->
      <a-form-item label="">
        <span>学　　位 ：</span>
            <j-dict-select-tag type="list" v-decorator="['professorDegree']" :trigger-change="true" dictCode="degree" placeholder="请选择学位"/>
          </a-form-item>
<!--        </a-col>-->
<!--      </a-row>-->
<!--      <a-row :gutter="24">-->
<!--        <a-col :span="8">-->
      <a-form-item label="">
        <span>工作单位 ：</span>
            <a-input v-decorator="['professorWorkUnit']" placeholder="请输入工作单位"></a-input>
          </a-form-item>
<!--        </a-col>-->
<!--      </a-row>-->

<!--      <a-row :gutter="24">-->
<!--        <a-col :span="8">-->
      <a-form-item label="">
      <span>通讯地址 ：</span>
            <a-input v-decorator="['professorAddress']" placeholder="请输入通讯地址"></a-input>
          </a-form-item>
<!--        </a-col>-->
<!--      </a-row>-->
<!--      <a-row :gutter="24">-->
<!--        <a-col :span="8">-->
      <a-form-item label="">
        <span>申报类别 ：</span>
            <j-category-select
              v-decorator="['professorDeclareCategory']"
              pcode="B03"
              multiple
            />
          </a-form-item>
<!--        </a-col>-->

<!--      </a-row>-->

<!--      <a-row :gutter="24">-->
<!--        <a-col :span="6">-->
      <a-form-item label="">
        <span>职　　务 ：</span>
<!--            <j-dict-select-tag type="list" v-decorator="['professorPosition']" :trigger-change="true" dictCode="position" placeholder="请选择职务"/>-->
            <a-input v-decorator="['professorPosition']" placeholder="请输入职务"></a-input>
          </a-form-item>
<!--        </a-col>-->
<!--      </a-row>-->
<!--      <a-row :gutter="24">-->
<!--        <a-col :span="6">-->

<!--        </a-col>-->
<!--      </a-row>-->
<!--      <a-row :gutter="24">-->
<!--        <a-col :span="6">-->
      <a-form-item label="">
        <span>技术职称 ：</span>
            <j-dict-select-tag type="list" v-decorator="['professorTitle']" :trigger-change="true" dictCode="job_title" placeholder="请选择技术职称"/>
          </a-form-item>
<!--        </a-col>-->
<!--      </a-row>-->

<!--      <a-row :gutter="24">-->
<!--        <a-col :span="6">-->
      <a-form-item label="">
        <span>从事专业 ：</span>
            <a-input v-decorator="['professorWorkMajor']" placeholder="请输入从事专业"></a-input>
          </a-form-item>
<!--        </a-col>-->
<!--      </a-row>-->
<!--      <a-row :gutter="24">-->
<!--        <a-col :span="6">-->
      <a-form-item label="">
        <span>参加工作时间 ：</span>
        <j-date placeholder="请选择参加工作时间" v-decorator="['professorBeginWork']" :trigger-change="true" />
      </a-form-item>
      <a-form-item label="">
        <span>从事专业时间 ：</span>
            <j-date placeholder="请选择从事专业时间" v-decorator="['professorMajorDate']" :trigger-change="true"/>
          </a-form-item>
      <a-form-item label="">
        <span>出生年月 ：</span>
        <j-date placeholder="请选择出生年月" v-decorator="['professorBirthday']" :trigger-change="true" />
      </a-form-item>
      <a-form-item  label="">
        <span>毕业时间 ：</span>
        <j-date placeholder="请选择毕业时间" v-decorator="['professorGraduateDate']" :trigger-change="true"/>
      </a-form-item>
<!--        </a-col>-->
<!--      </a-row>-->
<!--      <a-row :gutter="24">-->
<!--        <a-col :span="6">-->
      <a-form-item label="">
        <span>身份证号 ：</span>
            <a-input v-decorator="['professorIdentity']" placeholder="请输入身份证号"></a-input>
          </a-form-item>
<!--        </a-col>-->
<!--      </a-row>-->

<!--      <a-row :gutter="24">-->
<!--        <a-col :span="8">-->
      <a-form-item label="">
        <span>家庭地址 ：</span>
<!--            <j-area-linkage type="cascader" v-decorator="['professorHomeAddress']" placeholder="请输入省市区"/>-->
            <a-input v-decorator="['professorHomeAddress']" placeholder="请输入家庭地址"/>
          </a-form-item>
<!--        </a-col>-->
<!--      </a-row>-->
<!--      <a-row :gutter="24">-->
<!--        <a-col :span="8">-->
      <a-form-item label="">
        <span>健康状态 ：</span>
            <j-dict-select-tag type="list" v-decorator="['professorHealth']" :trigger-change="true" dictCode="health" placeholder="请选择健康状况"/>
          </a-form-item>
<!--        </a-col>-->
<!--      </a-row>-->

<!--      <a-row :gutter="24">-->
<!--        <a-col :span="8">-->
      <a-form-item label="">
        <span>联系方式 ：</span>
            <a-input addon-before="办公室" v-decorator="['professorOfficeTel']"/>
          </a-form-item>
<!--        </a-col>-->
<!--      </a-row>-->
<!--      <a-row :gutter="24">-->
<!--        <a-col :span="8">-->
      <a-form-item label="">
        <span>联系方式 ：</span>
            <a-input addon-before="手机" v-decorator="['professorPhone']"/>
          </a-form-item>
<!--        </a-col>-->
<!--      </a-row>-->
<!--      <a-row :gutter="24">-->
<!--        <a-col :span="18">-->
          <a-form-item label="">
            <span>本人支持或参加过的典型项目（包括项目名称、建设规模、投资额及所负责的内容）</span>
            <a-textarea  :rows="4" v-decorator="['professorProjectIntroduce']"/>
          </a-form-item>
<!--        </a-col>-->
<!--      </a-row>-->

<!--      <a-row :gutter="24">-->
<!--        <a-col :span="18">-->
          <a-form-item>
            <span>业务主管部门</span>
            <a-textarea :rows="4" v-decorator="['professorLeadMsg']"/>
          </a-form-item>
<!--        </a-col>-->
<!--      </a-row>-->

<!--      <a-row :gutter="24">-->
<!--        <a-col :span="18">-->
          <a-form-item >
            <span>行政审批局意见</span>
            <a-textarea :rows="4" v-decorator="['professorApproveMsg']" disabled/>
          </a-form-item>
<!--        </a-col>-->
<!--      </a-row>-->
      <a-row>
        <!--isMultiple 多选 :wrapperCol="wrapperCol"  :labelCol="labelCol"-->
        <!--        <a-col :span="6" style="position: absolute; left: 76%">-->
        <a-col>
          <a-form-item label="个人照片" >
            <j-image-upload  v-decorator="['professorPhotoString']"></j-image-upload>
          </a-form-item>
        </a-col>
      </a-row>
      <a-row>
        <a-col>
          <!--          <a-col :span="6" style="position: absolute; left: 75% ">-->
          <div>
            <a-form-item label="申请表照片">
              <j-image-upload  v-decorator="['professorInfoPhotoString']"></j-image-upload>
            </a-form-item>
          </div>
        </a-col>
      </a-row>
      <a-row>
        <a-col>
          <!--          <a-col :span="6" style="position: absolute; left: 75% ">-->
          <div>
            <a-form-item label="身份证复印件">
              <j-image-upload v-decorator="['professorIdString']"></j-image-upload>
            </a-form-item>
          </div>
        </a-col>
      </a-row>
      <a-row>
        <a-col>
          <!--          <a-col :span="6" style="position: absolute; left: 75% ">-->
          <div>
            <a-form-item label="个人承诺书">
              <j-image-upload v-decorator="['professorCommitmentString']"></j-image-upload>
            </a-form-item>
          </div>
        </a-col>
      </a-row>
      <a-row>
        <a-col>
          <!--          <a-col :span="6" style="position: absolute; left: 75% ">-->
          <div>
            <a-form-item label="个人工作简历">
              <j-image-upload multiple isMultiple showUploadList  v-decorator="['professorResumeString']"></j-image-upload>
            </a-form-item>
          </div>
        </a-col>
      </a-row>
      <a-row>
        <a-col>
          <!--          <a-col :span="6" style="position: absolute; left: 75% ">-->
          <div>
            <a-form-item label="学历、学位证书复印件">
              <j-image-upload multiple isMultiple showUploadList  v-decorator="['professorDegreeImageString']"></j-image-upload>
            </a-form-item>
          </div>
        </a-col>
      </a-row>
      <a-row>
        <a-col>
          <!--          <a-col :span="6" style="position: absolute; left: 75% ">-->
          <div>
            <a-form-item label="专业资格职业证书复印件">
              <j-image-upload multiple isMultiple showUploadList  v-decorator="['professorQualificationString']"></j-image-upload>
            </a-form-item>
          </div>
        </a-col>
      </a-row>
      <a-row>
        <a-col>
          <!--          <a-col :span="6" style="position: absolute; left: 75% ">-->
          <div>
            <a-form-item label="其他证明专业能力的材料">
              <j-image-upload multiple isMultiple showUploadList  v-decorator="['professorOtherString']"></j-image-upload>
            </a-form-item>
          </div>
        </a-col>
      </a-row>

          <a-button type="primary" @click="handleOk" :style="{ marginRight: '8px' }" :disabled="isdisabledF" v-if="isShow02">
            提交
          </a-button>
          <a-button type="primary" @click="SaveTemp" :style="{ marginRight: '8px' }" v-show="idShow01">
            保存
          </a-button>
          <a-button :style="{ marginRight: '8px' }" @click="add">
            清除
          </a-button>
          <a-button type="primary"  icon="download" @click="exportPDF">
              点击下载附件
            </a-button>

    </a-form>
  </div>
</template>
<script>
  import JDate from '@/components/jeecg/JDate'
  import JCategorySelect from '@/components/jeecg/JCategorySelect'
  import JTreeSelect from '@/components/jeecg/JTreeSelect'
  import pick from 'lodash.pick'
  import JAreaLinkage from '@comp/jeecg/JAreaLinkage'
  import ATextarea from "ant-design-vue/es/input/TextArea";
  import { httpAction } from '@/api/manage'
  import {downloadFile} from '@/api/manage'
  // 导入
  import {getAction} from '@/api/manage'
  import JImageUpload from '@/components/jeecg/JImageUpload'
  import ACol from "ant-design-vue/es/grid/Col";
  import {postAction} from "../../api/manage";
  function getBase64(img, callback) {
    const reader = new FileReader();
    reader.addEventListener('load', () => callback(reader.result));
    reader.readAsDataURL(img);
  }
  export default {
    name:"DiyProfessorInfoWrite",
    components:{
      ACol,
      ATextarea,
      JAreaLinkage,
      JImageUpload,
      JCategorySelect,
      JDate,
      downloadFile
    },
    data() {
      return {
        idShow01:true,
        isShow02:true,
        isdisabledF:false,
        schoolId:"",
        marjorId:"",
        form:this.$form.createForm(this),
        imageUrl: '',
        model:{},
        validatorRules:{
        },
        url:"/sendToDing",
        downLoadUrl:'/professorInfo.xlsx',
        exportPdfUrl:"/org/exportProfessor/exportPDF",
        downloadPdfUrl:"/sys/common/static/",
      };
    },
    created(){
      this.select();
      this.seletidNull();
      this.selectisdiabaled();
      this.$notification.warning({
        message: '填写信息后请点击下载附件',
        description:
          '点击下载附件，打印填写的信息，有关部门审批之后提交申请表照片',
      })
    },
    mounted(){

    },
    methods: {
      next() {
        this.current++;
      },
      prev() {
        this.current--;
      },
      seletidNull(){
        getAction("/temporary/diyTemporaryApplicantInfo/seletidNull").then((res) => {
          if(res.result!=null){
            return this.idShow01=false;
          }
          else{
            return this.isShow02=false;
          }
        })
      },
      selectisdiabaled(){
        getAction("/temporary/diyTemporaryApplicantInfo/selectIsdisabledByuserid").then((res) => {
         if(res.result==1){
           return this.isdisabledF=true;
         }
        })
      },
      select(){
        getAction("/temporary/diyTemporaryApplicantInfo/selectByuserid").then((res) => {
          this.form.setFieldsValue({
            professorName:res.result.professorName,
            professorSex:res.result.professorSex,
            professorSchool:res.result.professorSchool,
            professorBirthday:res.result.professorBirthday,
            professorPhotoString:res.result.professorPhotoString,
            professorMajor:res.result.professorMajor,
            professorGraduateDate:res.result.professorGraduateDate,
            professorEducationBackground:res.result.professorEducationBackground,
            professorDegree:res.result.professorDegree,
            professorWorkUnit:res.result.professorWorkUnit,
            professorAddress:res.result.professorAddress,
            professorDeclareCategory:res.result.professorDeclareCategory,
            professorPosition:res.result.professorPosition,
            professorBeginWork:res.result.professorBeginWork,
            professorTitle:res.result.professorTitle,
            professorWorkMajor:res.result.professorWorkMajor,
            professorMajorDate:res.result.professorMajorDate,
            professorIdentity:res.result.professorIdentity,
            professorHomeAddress:res.result.professorHomeAddress,
            professorHealth:res.result.professorHealth,
            professorOfficeTel:res.result.professorOfficeTel,
            professorPhone:res.result.professorPhone,
            professorProjectIntroduce:res.result.professorProjectIntroduce,
            professorLeadMsg:res.result.professorLeadMsg,
            professorApproveMsg:res.result.professorApproveMsg,
            professorInfoPhotoString:res.result.professorInfoPhotoString,
            professorIdString:res.result.professorIdString,
            professorCommitmentString:res.result.professorCommitmentString,
            professorResumeString:res.result.professorResumeString,
            professorDegreeImageString:res.result.professorDegreeImageString,
            professorQualificationString:res.result.professorQualificationString,
            professorOtherString:res.result.professorOtherString,
          });
        });
        },
      selSchool(){
        let searchText=this.$refs.searchVal.value;
        console.log(searchText);
      },
      // handleChange(info) {
      //   if (info.file.status === 'uploading') {
      //     this.loading = true;
      //     return;
      //   }
      //   if (info.file.status === 'done') {
      //     // Get this url from response in real world.
      //     getBase64(info.file.originFileObj, imageUrl => {
      //       this.imageUrl = imageUrl;
      //       this.loading = false;
      //     });
      //   }
      // },
      // beforeUpload(file) {
      //   const isJpgOrPng = file.type === 'image/jpeg' || file.type === 'image/png';
      //   if (!isJpgOrPng) {
      //     this.$message.error('You can only upload JPG file!');
      //   }
      //   const isLt2M = file.size / 1024 / 1024 < 2;
      //   if (!isLt2M) {
      //     this.$message.error('Image must smaller than 2MB!');
      //   }
      //   return isJpgOrPng && isLt2M;
      // },
      add () {
        this.edit({});
      },
      edit (record) {
        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
        this.$nextTick(() => {
          /**
           *  我添加的    ,'professorBirthday','professorSchool','professorMajor','professorGraduateDate','professorEducationBackground','professorDegree','professorWorkUnit'
           ,'professorAddress','professorPosition','professorBeginWork','professorTitle','professorWorkMajor','professorMajorDate','professorIdentity'
           */
          this.form.setFieldsValue(pick(this.model,'professorInfoPhotoString','professorPhotoString','professorDeclareCategory','professorName','professorSex','professorBirthday','professorSchool','professorMajor','professorGraduateDate','professorEducationBackground','professorDegree','professorWorkUnit'
            ,'professorAddress','professorPosition','professorBeginWork','professorTitle','professorWorkMajor','professorMajorDate','professorIdentity','professorHomeAddress',
            'professorOfficeTel','professorPhone','professorProjectIntroduce','professorLeadMsg','professorApproveMsg','professorHomeAddress','professorHealth'))
        })
      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
      SaveTemp(){
        const that = this;
        // 触发表单验证
        this.form.validateFields((err, values) => {
          // 获取表单中type的id
          let formType = that.form.getFieldValue("professorDeclareCategory");
          // 访问后台，查找hasChild
          let formRealType = "";
          let url = "/sys/category/findById?ids="+formType;
          getAction(url).then((res) => {
            if (res.success) {
              formRealType = res.result;
              if(formRealType==0) {
                if (!err) {
                  let method = '';
                  method = 'post';
                  let formData = Object.assign(this.model, values);
                  httpAction("/temporary/diyTemporaryApplicantInfo/SaveTemp",formData,method).then((res)=>{
                    if(res.success){
                      that.$message.success(res.message);
                      that.$emit('ok');
                      location.reload();
                    }else{
                      that.$message.warning(res.message);
                    }
                  }).finally(() => {
                    that.confirmLoading = false;
                    that.close();
                  })
                }
              }else{
                this.$message.error("请选择具体的申报类型！")
              }
            }
          });
        })
      },
      exportPDF(){
        this.form.validateFields((err, values) => {
          let formData = Object.assign(this.model, values);
          postAction(this.exportPdfUrl,formData).then((res)=>{
            let url = this.downloadPdfUrl+res.message
            let a = document.createElement('a') //创建a标签
            a.href = window._CONFIG['domianURL']+url
            a.click()
            /*let url = this.downloadPdfUrl+'?filePath='+res.message
            // 根据url下载pdf
            this.axios({
              method: "get",
              url: url,
              responseType: 'blob',
            }).then((res)=>{
              // pdf下载
              console.log(res)
              let blob = new Blob([res], {type: 'application/pdf'});
              let downloadElement = document.createElement("a");
              let href = window.URL.createObjectURL(blob); //创建下载的链接
              downloadElement.href = href;
              // downloadElement.download = fileName; //下载后文件名
              downloadElement.download = "信息表"; //下载后文件名
              document.body.appendChild(downloadElement);
              downloadElement.click(); //点击下载
              document.body.removeChild(downloadElement); //下载完成移除元素
              window.URL.revokeObjectURL(href); //释放掉blob对象
            })*/


          })


        })
      },
      handleOk (){
        console.log("进入提交");
        const that = this;
        // 触发表单验证
        console.log("================"+this.model);
        this.form.validateFields((err, values) => {
          // 获取表单中type的id
          let formType = that.form.getFieldValue("professorDeclareCategory");
          // alert(formType);
          // 访问后台，查找hasChild
          let formRealType = "";
          let url = "/sys/category/findById?ids="+formType;
          console.log(url);
          getAction(url).then((res) => {
            if (res.success) {
              // alert("hasChild = " + res.result);
              formRealType = res.result;
              //  alert(formRealType==null)
              if(formRealType==0) {
                if (!err) {
                  console.log("进入提交状态");
                  console.log(err);
                  console.log(values);
                  let httpurl = '';
                  let method = '';
                  httpurl+=this.url;
                  method = 'post';
                  let formData = Object.assign(this.model, values);
                  console.log("表单提交数据",formData);
                  httpAction(httpurl,formData,method).then((res)=>{
                    console.log("res:"+res);
                    if(res.success){
                      console.log("res:"+res);
                      that.$message.success(res.message);
                      that.$emit('ok');
                      getAction("/temporary/diyTemporaryApplicantInfo/updateIsdisabledByuserid").then((res) => {});
                      location.reload();
                    }else{
                      that.$message.warning(res.message);
                    }
                  }).finally(() => {
                    that.confirmLoading = false;
                    that.close();
                  })
                }
              }else{
                this.$message.error("请选择具体的申报类型！")
              }
            }
          });
        })
      }
    },
  };
</script>
<style>
  .steps-content {
    margin-top: 16px;
    border: 1px dashed #e9e9e9;
    border-radius: 6px;
    background-color: #fafafa;
    min-height: 200px;
    text-align: center;
    padding-top: 80px;
  }

  .steps-action {
    margin-top: 24px;
  }
  .ant-advanced-search-form {
    padding: 24px;
    background: #fbfbfb;
    border: 1px solid #d9d9d9;
    border-radius: 6px;
  }

  .ant-advanced-search-form .ant-form-item {
    display: flex;
  }

  .ant-advanced-search-form .ant-form-item-control-wrapper {
    flex: 1;
  }
  .avatar-uploader > .ant-upload {
    width: 128px;
    height: 128px;
  }
  .ant-upload-select-picture-card i {
    font-size: 32px;
    color: #999;
  }

  .ant-upload-select-picture-card .ant-upload-text {
    margin-top: 8px;
    color: #666;
  }

  #components-form-demo-advanced-search .ant-form {
    max-width: none;
  }
  #components-form-demo-advanced-search .search-result-list {
    margin-top: 16px;
    border: 1px dashed #e9e9e9;
    border-radius: 6px;
    background-color: #fafafa;
    min-height: 200px;
    text-align: center;
    padding-top: 80px;
  }
</style>